package main

import (
	"AttackTracer/Tracker/RPC"
	"AttackTracer/Tracker/config"
	"AttackTracer/Tracker/resourseMonitor"
	"fmt"
	"os"
)

var (
	Conf          config.Config
	IncidentChann = make(chan RPC.Incident, 10)
)

func init() {
	// get config file path from command line
	var configPath string
	if len(os.Args) != 2 {
		fmt.Println("no config file provided")
		configPath = "/etc/AttackTracer/tracker.yaml"
	} else {
		configPath = os.Args[1]
	}
	fmt.Println("reading config from " + configPath)

	// parse config
	Conf, err := Conf.Parse(configPath)
	if err != nil {
		fmt.Println(err.Error())
		os.Exit(1)
	}

	if err = Conf.Validate(); err != nil {
		fmt.Println(err.Error())
		os.Exit(1)
	}
	//log.Print(Conf)
}

func main() {
	fmt.Println("Tacker starting")

	// Incident Report test
	//IncidentChann <- RPC.Incident{
	//	Name:  "SayHello",
	//	Value: nil,
	//}

	go resourseMonitor.MonitorResourse()
	RPC.ConnectAnalyzer(Conf.RpcConf, IncidentChann)
}
